#include #include #include using namespace std; bool fileExists(string fileName); void main() { string fileName; cout << "file name? "; getline(cin,fileName); //only open the file for output if it does NOT exist while(fileExists(fileName)) { cout << fileName << " already exists " << endl; cout << "file name? "; getline(cin,fileName); } //use the fileName } bool fileExists(string fileName) { bool result = true; ifstream fileChecker(fileName.c_str()); if(fileChecker.fail()) { //the only reason for fileChecker to have failed is that it //did not exist result = false; } fileChecker.close(); return result; }